package com.kkb.utils;

import org.springframework.util.DigestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author:CoolTiger
 * @title: UserUtil
 * @projectName ssm_hospital
 * @description: TODO 用户工具类：密码加密、session取值
 * @date:2022/07/08/19:05:03
 **/
public class UserUtil {
    /**
     *  TODO 获取session中的用户名
     * @param request
     * @return
     */
    public static String getUserName(HttpServletRequest request){
        return (String) request.getSession().getAttribute("username");
    }

    /**
     * TODO 使用md5加密
     * @param password
     * @return
     */
    public static String MD5(String password){
        if (password != null){
            return DigestUtils.md5DigestAsHex(password.getBytes()).toUpperCase();
        }else {
            return null;
        }
    }
}
